package goroutine

import (
	"biliClient/core"
	"biliClient/global"
	"sync"
	"time"
)

//PullM3u8 ...
func PullM3u8(roomID string, wg *sync.WaitGroup, count int, timeOut int64) {
	defer wg.Done()
	for {
		startTime := time.Now().Unix()
		address := core.PlayURL(roomID)
		m3u8 := core.GetM3U8(address)
		for {
			if time.Now().Unix()-startTime > startTime {
				continue
			}
			time.Sleep(time.Second * 5)
			tsURL := core.GetTsURL(m3u8)
			if core.PullM3U8Stream(tsURL) {
			} else {
				global.Log.Errorf("%v 失败", count)
				continue
			}
		}
	}
}
